﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using OpenExpressApp.Module.WPF;
using Csla.Core;
using OpenExpressApp.Editors;

namespace OpenExpressApp.Module.WPF.Editors
{
    class GDataGridFileDataColumn : OpenDataGridColumn
    {
        private FileDataPropertyEditor _editor;

        public GDataGridFileDataColumn(BusinessObjectPropertyInfo info, IListObjectView view)
            : base(info, view)
        {
            this._editor = new FileDataPropertyEditor(this.PropertyInfo, this.View);
            this.MinWidth = 100;
        }

        public override IWPFPropertyEditor Editor
        {
            get
            {
                return this._editor;
            }
        }

        protected override FrameworkElement GenerateElement(DataGridCell cell, object dataItem)
        {
            TextBlock result = new TextBlock();
            //FileAttachment.Name
            Binding TextBinding = new Binding(PropertyInfo.LookupAttribute.LookupPropertyName + "."
                + ApplicationModel.GetBusinessObjectInfo(PropertyInfo.LookupAttribute.LookupType).TitleInfo.Name);
            result.SetBinding(TextBlock.TextProperty, TextBinding);
            return result;
        }
        protected override FrameworkElement GenerateEditingElement(DataGridCell cell, object dataItem)
        {
            FrameworkElement result = base.GenerateEditingElement(cell, dataItem);
            result.Width = cell.Column.ActualWidth;
            return result;
        }
    }
}

